home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE23 / EX1.C < prev    next >
C/C++ Source or Header  |  1995-03-22  |  2KB  |  61 lines

  1. #include <windows.h>
  2. #include <genstub.c>
  3.  
  4. #include <atomtest.h>
  5.  
  6. // Atom name - constant string.
  7. #define THE_ATOM               "A fun atom."
  8.  
  9. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  10. {
  11.    switch (uMsg)   // Process Windows messages.
  12.    {
  13.       case WM_CREATE: // Increase number of entries in top area of atom table to 73.
  14.               InitAtomTable( 73 );
  15.               return DefWindowProc( hWnd, uMsg, wParam, lParam );
  16.       case WM_COMMAND:   // Process menu options.
  17.               switch ( LOWORD( wParam ) )
  18.                   {
  19.                      case IDM_ADDATOM:       // Adds an atom.
  20.                               AddAtom( THE_ATOM );
  21.                               InvalidateRect( hWnd, NULL, TRUE );
  22.                               UpdateWindow( hWnd );
  23.                               break;
  24.                      case IDM_DELETEATOM:    // Delete an atom.
  25.                               if ( FindAtom( THE_ATOM ) )
  26.                                  DeleteAtom( FindAtom(THE_ATOM) );
  27.                               InvalidateRect( hWnd, NULL, TRUE );
  28.                               UpdateWindow( hWnd );
  29.                               break;
  30.                      case IDM_EXIT:
  31.                               DestroyWindow( hWnd );
  32.                               break;
  33.                   }
  34.                   break;
  35.       case WM_PAINT:
  36.             {   // Show the results of searching for an atom.
  37.                 PAINTSTRUCT ps;
  38.                 char szWorkArea[33], szBuffer[128];
  39.                 ATOM aAnAtom = INVALID_ATOM;
  40.                 BeginPaint( hWnd, &ps );
  41.                 if (aAnAtom = FindAtom( THE_ATOM )) {
  42.                    GetAtomName( aAnAtom, szWorkArea, 32 );
  43.                    wsprintf( szBuffer, "Atom '%s' was found.", szWorkArea );
  44.                 }
  45.                 else
  46.                    lstrcpy( szBuffer, "Atom must be added." );
  47.                 TextOut( ps.hdc, 0, 0, szBuffer, lstrlen( szBuffer ) );
  48.                 EndPaint( hWnd, &ps );
  49.             }
  50.             break ;
  51.       case WM_DESTROY: // Atom table is destroyed on exit.
  52.             PostQuitMessage( 0 );
  53.       break ;
  54.       default:
  55.          return DefWindowProc( hWnd, uMsg, wParam, lParam );
  56.    }
  57.    return( 0L ) ;
  58. }
  59.  
  60. #include <about.c>
  61.